{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "a877c9d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data has been written to 中诚大厦周边数据表格.xlsx\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import requests\n",
    "\n",
    "# 定义获取API数据的函数，添加分页参数\n",
    "def get_api_data(url, offset, limit):\n",
    "    response = requests.get(url, params={'offset': offset, 'limit': limit})\n",
    "    if response.status_code == 200:\n",
    "        return response.json().get('pois', [])\n",
    "    else:\n",
    "        print(f\"Error fetching data: {response.status_code}\")\n",
    "        return []\n",
    "\n",
    "# 定义API的URL\n",
    "base_url = 'https://restapi.amap.com/v3/place/around?key=eca5e60c4f1ef3764871a52497c013ec&location=114.277158,30.592578&radius=10000&types=070500'\n",
    "\n",
    "# 设置分页参数\n",
    "pages = 5\n",
    "rows_per_page = 25\n",
    "offset = 0\n",
    "\n",
    "# 初始化一个空列表来存储所有数据\n",
    "all_data = []\n",
    "\n",
    "# 循环获取数据，共5页\n",
    "for _ in range(pages):\n",
    "    api_data = get_api_data(base_url, offset, rows_per_page)\n",
    "    all_data.extend(api_data)\n",
    "    offset += rows_per_page  # 更新offset以获取下一页数据\n",
    "\n",
    "# 将获取到的数据转换为DataFrame\n",
    "df = pd.DataFrame(all_data)\n",
    "\n",
    "# 将数据写入Excel文件，每个工作表存储一页数据\n",
    "excel_filename = '中诚大厦周边数据表格.xlsx'\n",
    "with pd.ExcelWriter(excel_filename, engine='openpyxl') as writer:\n",
    "    for i in range(pages):\n",
    "        # 计算每个工作表的数据范围\n",
    "        start_index = i * rows_per_page\n",
    "        end_index = start_index + rows_per_page\n",
    "        # 写入数据到不同的工作表\n",
    "        df.iloc[start_index:end_index].to_excel(writer, sheet_name=f'Page_{i+1}', index=False)\n",
    "\n",
    "print(f\"Data has been written to {excel_filename}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "6dbe51d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data has been written to 武银大厦周边数据表格.xlsx\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import requests\n",
    "\n",
    "# 定义获取API数据的函数，添加分页参数\n",
    "def get_api_data(url, offset, limit):\n",
    "    response = requests.get(url, params={'offset': offset, 'limit': limit})\n",
    "    if response.status_code == 200:\n",
    "        return response.json().get('pois', [])\n",
    "    else:\n",
    "        print(f\"Error fetching data: {response.status_code}\")\n",
    "        return []\n",
    "\n",
    "# 定义API的URL\n",
    "base_url = 'https://restapi.amap.com/v3/place/around?key=eca5e60c4f1ef3764871a52497c013ec&location=114.273599,30.596733&radius=10000&types=070500'\n",
    "\n",
    "# 设置分页参数\n",
    "pages = 5\n",
    "rows_per_page = 25\n",
    "offset = 0\n",
    "\n",
    "# 初始化一个空列表来存储所有数据\n",
    "all_data = []\n",
    "\n",
    "# 循环获取数据，共5页\n",
    "for _ in range(pages):\n",
    "    api_data = get_api_data(base_url, offset, rows_per_page)\n",
    "    all_data.extend(api_data)\n",
    "    offset += rows_per_page  # 更新offset以获取下一页数据\n",
    "\n",
    "# 将获取到的数据转换为DataFrame\n",
    "df = pd.DataFrame(all_data)\n",
    "\n",
    "# 将数据写入Excel文件，每个工作表存储一页数据\n",
    "excel_filename = '武银大厦周边数据表格.xlsx'\n",
    "with pd.ExcelWriter(excel_filename, engine='openpyxl') as writer:\n",
    "    for i in range(pages):\n",
    "        # 计算每个工作表的数据范围\n",
    "        start_index = i * rows_per_page\n",
    "        end_index = start_index + rows_per_page\n",
    "        # 写入数据到不同的工作表\n",
    "        df.iloc[start_index:end_index].to_excel(writer, sheet_name=f'Page_{i+1}', index=False)\n",
    "\n",
    "print(f\"Data has been written to {excel_filename}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "7d5bc42c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Data has been written to 良友大厦周边数据表格.xlsx\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import requests\n",
    "\n",
    "# 定义获取API数据的函数，添加分页参数\n",
    "def get_api_data(url, offset, limit):\n",
    "    response = requests.get(url, params={'offset': offset, 'limit': limit})\n",
    "    if response.status_code == 200:\n",
    "        return response.json().get('pois', [])\n",
    "    else:\n",
    "        print(f\"Error fetching data: {response.status_code}\")\n",
    "        return []\n",
    "\n",
    "# 定义API的URL\n",
    "base_url = 'https://restapi.amap.com/v3/place/around?key=eca5e60c4f1ef3764871a52497c013ec&location=114.273801,30.59283&radius=10000&types=070500'\n",
    "\n",
    "# 设置分页参数\n",
    "pages = 5\n",
    "rows_per_page = 25\n",
    "offset = 0\n",
    "\n",
    "# 初始化一个空列表来存储所有数据\n",
    "all_data = []\n",
    "\n",
    "# 循环获取数据，共5页\n",
    "for _ in range(pages):\n",
    "    api_data = get_api_data(base_url, offset, rows_per_page)\n",
    "    all_data.extend(api_data)\n",
    "    offset += rows_per_page  # 更新offset以获取下一页数据\n",
    "\n",
    "# 将获取到的数据转换为DataFrame\n",
    "df = pd.DataFrame(all_data)\n",
    "\n",
    "# 将数据写入Excel文件，每个工作表存储一页数据\n",
    "excel_filename = '良友大厦周边数据表格.xlsx'\n",
    "with pd.ExcelWriter(excel_filename, engine='openpyxl') as writer:\n",
    "    for i in range(pages):\n",
    "        # 计算每个工作表的数据范围\n",
    "        start_index = i * rows_per_page\n",
    "        end_index = start_index + rows_per_page\n",
    "        # 写入数据到不同的工作表\n",
    "        df.iloc[start_index:end_index].to_excel(writer, sheet_name=f'Page_{i+1}', index=False)\n",
    "\n",
    "print(f\"Data has been written to {excel_filename}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b84b3091",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "288a8b30",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
